/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/domain/{{entities@SQL}}.java.hbs
 */
package cn.ibizlab.core.open.domain;

import java.util.*;
import cn.ibizlab.util.domain.IEntity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.util.*;
import org.springframework.data.annotation.*;
import cn.ibizlab.util.annotation.*;
import cn.ibizlab.util.enums.*;
import cn.ibizlab.util.domain.EntityMP;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.Accessors;
import io.swagger.annotations.*;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import cn.ibizlab.core.open.domain.OpenAccess;
import cn.ibizlab.core.ad.domain.SysPerson;

/**
 * 接入认证绑定实体类[OpenAccessAuth]
 *
 * @author generator
 */
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
@TableName(value = "OPEN_ACCESS_AUTH", resultMap = "OpenAccessAuthResultMap")
@ApiModel(value = "OPEN_ACCESS_AUTH", description = "接入认证绑定")
public class OpenAccessAuth extends EntityMP implements Serializable
{

    /**
     * 标识
     */
    @Id
    @TableId(value = "id" , type = IdType.ASSIGN_UUID)
    @DEField(name = "id" , isKeyField = true)
    @JsonProperty("id")
    @JSONField(name = "id")
    @ApiModelProperty(value = "id", notes = "标识")
    private String id;

    /**
     * 第三方用户全局名
     */
    @TableField(value = "name")
    @DEField(name = "name")
    @JsonProperty("name")
    @JSONField(name = "name")
    @ApiModelProperty(value = "name", notes = "第三方用户全局名")
    private String name;

    /**
     * 第三方用户凭据
     */
    @TableField(value = "credential")
    @DEField(name = "credential")
    @JsonProperty("credential")
    @JSONField(name = "credential")
    @ApiModelProperty(value = "credential", notes = "第三方用户凭据")
    private String credential;

    /**
     * 创建人
     */
    @TableField(value = "creator" , fill = FieldFill.INSERT)
    @DEField(name = "creator" , preType = DEPredefinedFieldType.CREATEMAN)
    @JsonProperty("creator")
    @JSONField(name = "creator")
    @ApiModelProperty(value = "creator", notes = "创建人")
    private String creator;

    /**
     * 创建时间
     */
    @TableField(value = "create_time" , fill = FieldFill.INSERT)
    @DEField(name = "create_time" , preType = DEPredefinedFieldType.CREATEDATE)
    @JsonProperty("create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "create_time" , format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "create_time", notes = "创建时间")
    private Date createTime;

    /**
     * 最后更新人
     */
    @TableField(value = "updater")
    @DEField(name = "updater" , preType = DEPredefinedFieldType.UPDATEMAN)
    @JsonProperty("updater")
    @JSONField(name = "updater")
    @ApiModelProperty(value = "updater", notes = "最后更新人")
    private String updater;

    /**
     * 最后更新时间
     */
    @TableField(value = "update_time")
    @DEField(name = "update_time" , preType = DEPredefinedFieldType.UPDATEDATE)
    @JsonProperty("update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", locale = "zh", timezone = "GMT+8")
    @JSONField(name = "update_time" , format = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "update_time", notes = "最后更新时间")
    private Date updateTime;

    /**
     * DC
     */
    @TableField(value = "dc")
    @DEField(name = "dc")
    @JsonProperty("dc")
    @JSONField(name = "dc")
    @ApiModelProperty(value = "dc", notes = "DC")
    private String dc;

    /**
     * 人员标识
     */
    @TableField(value = "person_id")
    @DEField(name = "person_id")
    @JsonProperty("person_id")
    @JSONField(name = "person_id")
    @ApiModelProperty(value = "person_id", notes = "人员标识")
    private String personId;

    /**
     * 用户全局名(uid/loginname)
     */
    @TableField(value = "uid")
    @DEField(name = "uid")
    @JsonProperty("uid")
    @JSONField(name = "uid")
    @ApiModelProperty(value = "uid", notes = "用户全局名(uid/loginname)")
    private String uid;

    /**
     * 接入标识
     */
    @TableField(value = "access_id")
    @DEField(name = "access_id")
    @JsonProperty("access_id")
    @JSONField(name = "access_id")
    @ApiModelProperty(value = "access_id", notes = "接入标识")
    private String accessId;

    /**
     * RefreshToken标识
     */
    @TableField(value = "refresh_token")
    @DEField(name = "refresh_token")
    @JsonProperty("refresh_token")
    @JSONField(name = "refresh_token")
    @ApiModelProperty(value = "refresh_token", notes = "RefreshToken标识")
    private String refreshToken;

    /**
     * Token标识
     */
    @TableField(value = "token_id")
    @DEField(name = "token_id")
    @JsonProperty("token_id")
    @JSONField(name = "token_id")
    @ApiModelProperty(value = "token_id", notes = "Token标识")
    private String tokenId;

    /**
     * token
     */
    @TableField(value = "token")
    @DEField(name = "token")
    @JsonProperty("token")
    @JSONField(name = "token")
    @ApiModelProperty(value = "token", notes = "token")
    private String token;

    /**
     * 第三方用户详细信息
     */
    @TableField(value = "params")
    @DEField(name = "params")
    @JsonProperty("params")
    @JSONField(name = "params")
    @ApiModelProperty(value = "params", notes = "第三方用户详细信息")
    private String params;

    /**
     * 接入类型
     */
    @TableField(value = "access_type" , exist = false)
    @DEField(name = "access_type" , dict = "Open_access_type_justAuth")
    @JsonProperty("access_type")
    @JSONField(name = "access_type")
    @ApiModelProperty(value = "access_type", notes = "接入类型")
    private String accessType;

    /**
     * 接入名称
     */
    @TableField(value = "access_name" , exist = false)
    @DEField(name = "access_name")
    @JsonProperty("access_name")
    @JSONField(name = "access_name")
    @ApiModelProperty(value = "access_name", notes = "接入名称")
    private String accessName;

    /**
     * 手机号
     */
    @TableField(value = "mobile" , exist = false)
    @DEField(name = "mobile")
    @JsonProperty("mobile")
    @JSONField(name = "mobile")
    @ApiModelProperty(value = "mobile", notes = "手机号")
    private String mobile;

    /**
     * 头像
     */
    @TableField(value = "avatar" , exist = false)
    @DEField(name = "avatar")
    @JsonProperty("avatar")
    @JSONField(name = "avatar")
    @ApiModelProperty(value = "avatar", notes = "头像")
    private String avatar;

    /**
     * 邮箱
     */
    @TableField(value = "mail" , exist = false)
    @DEField(name = "mail")
    @JsonProperty("mail")
    @JSONField(name = "mail")
    @ApiModelProperty(value = "mail", notes = "邮箱")
    private String mail;

    /**
     * 开放接入
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    @Transient
    @ApiModelProperty(value = "open_access", notes = "接入平台")
    private OpenAccess openAccess;

    /**
     * 人员
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    @Transient
    @ApiModelProperty(value = "person", notes = "人员")
    private SysPerson person;

    /**
     * 设置 [第三方用户全局名]
     */
    public OpenAccessAuth setName(String name) {
        this.name = name;
        this.modify("name", name);
        return this;
    }

    /**
     * 设置 [第三方用户凭据]
     */
    public OpenAccessAuth setCredential(String credential) {
        this.credential = credential;
        this.modify("credential", credential);
        return this;
    }

    /**
     * 设置 [DC]
     */
    public OpenAccessAuth setDc(String dc) {
        this.dc = dc;
        this.modify("dc", dc);
        return this;
    }

    /**
     * 设置 [人员标识]
     */
    public OpenAccessAuth setPersonId(String personId) {
        this.personId = personId;
        this.modify("person_id", personId);
        return this;
    }

    /**
     * 设置 [用户全局名(uid/loginname)]
     */
    public OpenAccessAuth setUid(String uid) {
        this.uid = uid;
        this.modify("uid", uid);
        return this;
    }

    /**
     * 设置 [接入标识]
     */
    public OpenAccessAuth setAccessId(String accessId) {
        this.accessId = accessId;
        this.modify("access_id", accessId);
        return this;
    }

    /**
     * 设置 [RefreshToken标识]
     */
    public OpenAccessAuth setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
        this.modify("refresh_token", refreshToken);
        return this;
    }

    /**
     * 设置 [Token标识]
     */
    public OpenAccessAuth setTokenId(String tokenId) {
        this.tokenId = tokenId;
        this.modify("token_id", tokenId);
        return this;
    }

    /**
     * 设置 [token]
     */
    public OpenAccessAuth setToken(String token) {
        this.token = token;
        this.modify("token", token);
        return this;
    }

    /**
     * 设置 [第三方用户详细信息]
     */
    public OpenAccessAuth setParams(String params) {
        this.params = params;
        this.modify("params", params);
        return this;
    }

    /**
     * 设置 [接入类型]
     */
    public OpenAccessAuth setAccessType(String accessType) {
        this.accessType = accessType;
        this.modify("access_type", accessType);
        return this;
    }

    /**
     * 设置 [接入名称]
     */
    public OpenAccessAuth setAccessName(String accessName) {
        this.accessName = accessName;
        this.modify("access_name", accessName);
        return this;
    }

    /**
     * 设置 [手机号]
     */
    public OpenAccessAuth setMobile(String mobile) {
        this.mobile = mobile;
        this.modify("mobile", mobile);
        return this;
    }

    /**
     * 设置 [头像]
     */
    public OpenAccessAuth setAvatar(String avatar) {
        this.avatar = avatar;
        this.modify("avatar", avatar);
        return this;
    }

    /**
     * 设置 [邮箱]
     */
    public OpenAccessAuth setMail(String mail) {
        this.mail = mail;
        this.modify("mail", mail);
        return this;
    }


    @Override
    public Serializable getDefaultKey(boolean gen) {
        //Assert.notNull(getAccessId(),"未设置接入标识");
        //Assert.notNull(getPersonId(),"未设置人员标识");
        String key = String.format("%s||%s"
            ,getAccessId(),getPersonId());
        key = DigestUtils.md5DigestAsHex(key.getBytes());    
        return key;
    }

    /**
     * 复制当前对象数据到目标对象(粘贴重置)
     * @param targetEntity 目标数据对象
     * @param includeEmpty  是否包括空值
     * @param <T>
     * @return
     */
    @Override
    public <T> T pasteTo(T targetEntity, boolean includeEmpty) {
        super.pasteTo(targetEntity, includeEmpty);
        if(targetEntity instanceof IEntity) {
            IEntity entity = ((IEntity) targetEntity);
            entity.reset("id");
        }
        return targetEntity;
    }

}